<template>
  <div id="app">
    <el-form :model="useb" label-width="80px">
      <el-form-item label="用户名" >
        <el-input v-model="useb.name"></el-input>
      </el-form-item>

      <el-form-item label="头像">
        <el-upload
          class="avatar-uploader"
          :show-file-list="false"
          action="http://localhost:8999/springboot-day1/usebs/upload"
          name="headImg"
          :with-credentials="true"
          list-type="picture"
          accept=".png,.jpg"
          :on-success="handleOnSuccess"
           >
          <img v-if="imageUrl" :src="imageUrl" class="avatar">
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click.prevent="test">注册</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
     name: "uplodaFile",
       data(){
       return {
         useb:{},
         imageUrl:""
       }
     },
    methods:{
        handleOnSuccess(resp ,file){
         //console.log(resp);
         console.log(file);
        this.imageUrl="http://localhost:8999/springboot-day1/"+file.name;
        },
      test(){
          this.useb.imgpash=this.imageUrl;//
          this.axios.post("usebs",this.useb)
        .then((resp)=>{
          this.$message.success("添加成功!");
          this.$router.push("/UsebTable");
        });
      }

   }

}
</script>

<style scoped>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}


</style>
